﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Data;

public partial class MainMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        DataTable dt = (DataTable)this.Cache["pendingobjects"];
        object sum = dt.Compute("sum(count)", null);
        if (string.IsNullOrEmpty(sum.ToString()))
            sum = (int)(0);
        string str = this.GetGlobalResourceObject("Resource", "PendingObjectNumber").ToString();
        PendingObjectsNumberLinkButton.Text = str + "<font  color='red'>" + sum.ToString()+ "</font>"  ;

        if (!Page.IsPostBack)
        {
            if (!Page.IsPostBack)
            {
                if ((Session["role_id"] != null) && (int.Parse(Session["role_id"].ToString()) != 1))
                {
                    Response.Redirect("~/Default.aspx");

                }



                else
                {
                    //logincontainer.Visible = false;
                    logout.Visible = true;
                    users.Text = Session["user"].ToString().Split(',')[0];


                }
            }

            if (Session["user"] != null)
            {
                lk1.NavigateUrl = Session["url"].ToString();
            }
        }
    }

    protected void Page_Init(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
            if ((Session["role_id"] == null) || (int.Parse(Session["role_id"].ToString()) != 1))
            {
                Response.Redirect("~/Default.aspx");

            }
            else
            {
                logout.Visible = true;
            }

        }

    }
    //protected override void   InitializeCulture()
    //{
    //    string lang = Request["Language1"];
    //    if (lang != null && lang != "")
    //    {
    //        Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
    //        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
    //    }
    //}
    protected void Language1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //string lang = Language1.SelectedValue;
        //if (lang != null && lang != "0")
        //{
        //    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
        //    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
        //    Session["CurrentCulture"]=lang;
        //    Server.Transfer(Request.Path);  
        //}
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA");
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ar-SA");
        Session["CurrentCulture"] = "ar-SA";
        Server.Transfer(Request.Path);  
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
        Session["CurrentCulture"] = "en-US";
        Server.Transfer(Request.Path);  
    }
    protected void LinkButton8_Click(object sender, EventArgs e)
    {
        DB.UPDATE("mysettings", "int,id,1", "logininout", "int","getdate()");//("g", culture));
        string  obj = Session["CurrentCulture"].ToString();
        Session.Clear();
        Session["CurrentCulture"] = obj;
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(obj);
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(obj);
        Response.Redirect("~/Default.aspx");
    }

}
